home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / SEARCH.MUT < prev    next >
Text File  |  1992-11-09  |  2KB  |  85 lines

  1. ;; search.mut : For those times when you don't want to use incremental
  2. ;;   search.
  3. ;; C Durland    Public Domain
  4.  
  5. (string search-pattern re-search-pattern)
  6.  
  7. (defun
  8.   MAIN
  9.   {
  10. ;    (bind-to-key "forward-search"    "C-s")
  11. ;    (bind-to-key "reverse-search"    "C-r")
  12.     (bind-to-key "forward-re-search"    "M-C-s")
  13.   }
  14.   forward-search
  15.   {
  16.     (and
  17.       (get-search-pattern "Forward search" search-pattern)
  18.       (not (search-forward search-pattern))
  19.       { (msg "Not found") FALSE })
  20.   }
  21.   reverse-search
  22.   {
  23.     (and
  24.       (get-search-pattern "Reverse search" search-pattern)
  25.       (not (search-reverse search-pattern))
  26.       { (msg "Not found") FALSE })
  27.   }
  28.   forward-re-search
  29.   {
  30.     (and
  31.       (get-search-pattern "Forward RE search" re-search-pattern)
  32.       (not (re-search-forward re-search-pattern))
  33.       { (msg "Not found") FALSE })
  34.   }
  35.   reverse-re-search
  36.   {
  37.     (and
  38.       (get-search-pattern "Reverse RE search" re-search-pattern)
  39.       (not (re-search-reverse re-search-pattern))
  40.       { (msg "Not found") FALSE })
  41.   }
  42. )
  43.  
  44.  
  45.  
  46.     ;; Some routines copied from qr.mut
  47. (defun
  48.   get-search-pattern (string prompt pattern replace-pattern-default) HIDDEN
  49.   {
  50.     (string pat)
  51.  
  52.     (pat (prompt-and-ask prompt pattern))
  53.     (if (== "" pat)        ;; user hit Enter so use default
  54.       {
  55.     (if (== "" pattern)    ;; no default
  56.       { (msg "Gotta search for something!") FALSE (done) })
  57.     ;; old pattern exists and is good so use it
  58.       }
  59.       (if (== "^W" pat)        ;; C-W => look for word cursor is on
  60.     {
  61.       (if (looking-at '\w+')
  62.         {
  63.           ;;(replace-pattern-default "")  ;; clear replace pattern default
  64.           (pattern (get-matched '&'))   ;; use user entered pattern
  65.         }
  66.         { (msg "Not a word!") FALSE (done) })
  67.     }
  68.     {
  69.       ;;(replace-pattern-default "")    ;; clear replace pattern default
  70.       (pattern pat)            ;; use user entered pattern
  71.     }))
  72.     TRUE
  73.   }
  74. ;  prompt-and-ask (string prompt pattern) HIDDEN
  75. ;  {
  76. ;    (ask-user)
  77. ;    (ask
  78. ;      prompt
  79. ;      (if (!= "" pattern)            ;; old pattern exists
  80. ;    (concat " [" pattern "]")        ;; prompt [pattern]:
  81. ;    "")
  82. ;      ": ")
  83. ;  }
  84. )
  85.